import Watcher from './Watcher.js'
import Updater from './Updater.js'

export default {
  // v-text指令处理
  text(vm, node, attValue) {
    Updater.text(vm, node, vm[attValue])
    new Watcher(vm, attValue, (value) => {
      Updater.text(vm, node, value)
    })
  },
  //   v-module指令处理
  model(vm, node, attValue) {
    Updater.model(vm, node, vm[attValue])
    new Watcher(vm, attValue, (value) => {
      Updater.model(vm, node, value)
    })
    node.addEventListener('input', () => {
      vm[attValue] = node.value
    })
  },
  html(vm, node, attValue) {
    Updater.html(vm, node, vm[attValue])
    new Watcher(vm, attValue, (value) => {
      Updater.html(vm, node, value)
    })
  },
  on(vm, node, eventName, attValue) {
    const method = vm.$methods[attValue]
    node.addEventListener(eventName, function (event) {
      method.call(vm, event)
    })
  },
}
